﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WebApi.Core.IService;
using WebApi.Core.Model;

namespace WebApi.Core.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService<UserEntity> _userService;
        private readonly ILogger<UserController> _logger;

        public UserController(IUserService<UserEntity> userService, ILogger<UserController> logger)
        {
            _userService = userService;
            _logger = logger;
        }


        /// <summary>
        /// 根据id获取数据
        /// </summary>
        /// <param name="id">参数id</param>
        /// <returns></returns>
        //[HttpGet("{id}", Name = "Get")]
        [HttpGet]
        public async Task<IActionResult> GetUser(int id)
        {
            #region new方式
            //IUserService userService = new UserService();
            //UserEntity user = await userService.QueryByID(id);
            #endregion

            #region DI
            UserEntity user = await _userService.QueryByID(id);
            #endregion

            return Ok(user);
        }


    }
}